package com.getjsp.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.getjsp.bean.Column;
import com.getjsp.ui.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyListAdapter extends BaseAdapter {
	private Context context;
	private List<Column> column_list;
	@SuppressLint("UseSparseArrays")
	private Map<Integer, View> newsItemViews = new HashMap<Integer, View>();

	public MyListAdapter() {
		super();
	}

	public MyListAdapter(Context context, List<Column> column_list) {
		super();
		this.context = context;
		this.column_list = column_list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return column_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return column_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = newsItemViews.get(position);
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.fenlei_item,
					null);
			Column column = (Column) getItem(position);
			ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
			iv_icon.setImageDrawable(column.getIv_icon());
			TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
			tv_title.setText(column.getTitle());
			TextView tv_summary = (TextView) view.findViewById(R.id.tv_summary);
			tv_summary.setText(column.getSummar());
		}
		return view;
	}

}
